package com.hyc.entity;

import com.carrotsearch.sizeof.RamUsageEstimator;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.openjdk.jol.info.ClassLayout;
import org.openjdk.jol.info.GraphLayout;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class Employee {
    private Long id;
    private String name;
    private Integer age;

    public static void main(String[] args) {
        Employee emp = new Employee(1L, "张三", 23);
        System.out.println(RamUsageEstimator.sizeOf(emp));

        System.out.println("================================================================================================");
        //打印实例的内存布局
        System.out.println(ClassLayout.parseInstance(emp).toPrintable());
        System.out.println("=================================================");
        //打印对象的所有相关内存占用
        System.out.println(GraphLayout.parseInstance(emp).toPrintable());
        System.out.println("=================================================");
        //打印对象的所有内存结果并统计
        System.out.println(GraphLayout.parseInstance(emp).toFootprint());
    }
}
